**This document displays the commands for generating variables and regressions for Figures 5, 6, 7, 8, and 9, as well as Tables 1, 2, and A.1. **
** For the other Tables and Figures, please see "FPA_Military_Statecraft_Figures_Tables_1" and "FPA_Military_Statecraft_OLS"**

** Import MME Data **
import excel FPA_Military_Statecraft_Dyads.xlsx, firstrow clear

** Data, Variables, and Scalars **
* Declare data to be time-series cross-sectional (TSCS) *
egen dyad=group(ccode?)
xtset dyad year

* Generate and Label variables *
generate shapingmme1=1 if mme==1 & mmetype > 2
replace shapingmme1=0 if shapingmme1!=1
generate traditionalmme=1 if mme==1 & mmetype<3
replace traditionalmme=0 if mme==1 & mmetype>2
generate mmedv=2 if shapingmme==1
replace mmedv=1 if traditionalmme==1
replace mmedv=0 if mme==0
generate postcoldwar=1 if year>1991
replace postcoldwar=0 if year<1992
generate lagmmedv=L.mmedv
generate log_spending=log(mil_spending)
generate log_distance=log(distance)
label variable mmedv "Exercise Type"
label variable postcoldwar "Post-Cold War Uncertainty"
label variable lagmmedv "Previous Year Exercise"
label variable log_spending "Military Spending"
label variable ally "Ally"
label variable sameregion "Same Region"
label variable contiguity "Contiguity"
label variable colony_unit "Sovereign History"
label variable log_distance "Distance"
label define mmedvlabel 0 "No Exercise" 1 "Traditional Exercise" 2 "Shaping Exercise"
label values mmedv mmedvlabel

* Manually import doctrinal uncertainty values from Wordstat *
* After you download Wordstat, open the file "FPA_Military_Statecraft_Doctrinal_Uncertainty.ppj", click "Analyze", Run "Expert Mode" //
// choose the "Military_Statecraft_Categorization" file, and click the tab "Crosstab" to determine the frequencies below*
generate doct_uncertainty=1 if abbrev1=="USA"
replace doct_uncertainty=0 if year== 1980 | year==1981
replace doct_uncertainty=1.91 if abbrev1=="USA" & year==1982|year==1983|year==1984|year==1985
replace doct_uncertainty=.99 if abbrev1=="USA" & year== 1986|year==1987|year==1988|year==1989|year==1990|year==1991|year==1992
replace doct_uncertainty=2.12 if abbrev1=="USA" & year==1993|year==1994|year==1995|year==1996|year==1997|year==1998|year==1999|year==2000
replace doct_uncertainty=3.76 if abbrev1=="USA" & year==2001|year==2002|year==2003|year==2004|year==2005|year==2006|year==2007
replace doct_uncertainty=6.28 if abbrev1=="USA" & year==2008|year==2009|year==2010
replace doct_uncertainty=2.69 if abbrev1=="USA" & year==2011|year==2012|year==2013|year==2014|year==2015|year==2016
replace doct_uncertainty=. if abbrev1!="USA"
label variable doct_uncertainty "Doctrinal Uncertainty"

* Manually import Average Exercise Size (From "FPA_Military_Statecraft_Figures_Tables_1" *
generate ave_ex_size=1
replace ave_ex_size=37000 if year==1980
replace ave_ex_size=35630.77 if year==1981
replace ave_ex_size=31305.55 if year==1982
replace ave_ex_size=41137.5 if year==1983
replace ave_ex_size=41239.29 if year==1984
replace ave_ex_size= 21401.43 if year==1985
replace ave_ex_size=19995 if year==1986
replace ave_ex_size=24393.18 if year==1987
replace ave_ex_size=50009.09 if year==1988
replace ave_ex_size=54844.45 if year==1989
replace ave_ex_size=29900 if year==1990
replace ave_ex_size=22844.45 if year==1991
replace ave_ex_size=81709.09 if year==1992
replace ave_ex_size=83136 if year==1993
replace ave_ex_size=5282.083 if year==1994
replace ave_ex_size=8774.154 if year==1995
replace ave_ex_size=3512.5 if year==1996
replace ave_ex_size=7541.5 if year==1997
replace ave_ex_size=10517.65 if year==1998
replace ave_ex_size=74616.9 if year==1999
replace ave_ex_size=8078.933 if year==2000
replace ave_ex_size=9968.75 if year==2001
replace ave_ex_size=5831.8 if year==2002
replace ave_ex_size=2918.667 if year==2003
replace ave_ex_size=3671.737 if year==2004
replace ave_ex_size=5922.048 if year==2005
replace ave_ex_size=2681.177 if year==2006
replace ave_ex_size=4665.682 if year==2007
replace ave_ex_size=10286.25 if year==2008
replace ave_ex_size=7291.333 if year==2009
replace ave_ex_size=9206.667 if year==2010
replace ave_ex_size=17452.14  if year==2011
replace ave_ex_size=19211.36 if year==2012
replace ave_ex_size=17086.59 if year==2013
replace ave_ex_size=11817.78  if year==2014
replace ave_ex_size=14419.6 if year==2015
replace ave_ex_size=12026.25 if year==2016
generate log_ave_ex_size=log(ave_ex_size)
label variable log_ave_ex_size "Ave Exercise Size"

* Figure 5: Descriptive statistics *
format mmedv doct_uncertainty postcoldwar lagmmedv log_spending log_ave_ex_size ally log_distance contiguity colony_unit %9.3fc
summarize mmedv doct_uncertainty postcoldwar lagmmedv log_spending log_ave_ex_size ally log_distance contiguity colony_unit, format

* Install estout command packages *
help estout

* Table 1: Results for H1 and H2 *
quietly mlogit mmedv doct_uncertainty lagmmedv log_spending log_ave_ex_size ally log_distance contiguity colony_unit if abbrev1=="USA", vce(cluster dyad)
estimates store M1
quietly mlogit mmedv postcoldwar lagmmedv log_spending log_ave_ex_size ally log_distance contiguity colony_unit if abbrev1=="USA", vce(cluster dyad)
estimates store M2
quietly mlogit mmedv postcoldwar lagmmedv log_spending log_ave_ex_size ally log_distance contiguity colony_unit if abbrev1!="USA", vce(cluster dyad)
estimates store M3
quietly mlogit mmedv postcoldwar lagmmedv log_spending log_ave_ex_size ally log_distance contiguity colony_unit if abbrev1=="RUS", vce(cluster dyad)
estimates store M4

estout M1 M2 M3 M4, cells(b(star fmt(3)) se(par fmt(2)))   ///
   legend label varlabels(_cons constant)               ///
   stats(r2_p N bic, fmt(3 0))

* Install spost package "spost13_ado" for marginal change plots (from Long and Freese 2014) *   
help mchange   
   
* Figure 6: Marginal Change Plot for Model 1 *
quietly mlogit mmedv doct_uncertainty lagmmedv log_spending log_ave_ex_size ally log_distance contiguity colony_unit if abbrev1=="USA", vce(cluster dyad)
mchange
mchangeplot doct_uncertainty lagmmedv log_spending log_ave_ex_size ally log_distance contiguity colony_unit, varlabels graphregion(color(white)) sig(.05)

* Figure 7: Marginal Change Plot for Model 2 *
quietly mlogit mmedv postcoldwar lagmmedv log_spending log_ave_ex_size ally log_distance contiguity colony_unit if abbrev1=="USA", vce(cluster dyad)
mchange
mchangeplot postcoldwar lagmmedv log_spending ally log_ave_ex_size log_distance contiguity colony_unit, varlabels graphregion(color(white)) sig(.05)
 
* Figure 8: Marginal Change Plot for Model 3 *
quietly mlogit mmedv postcoldwar lagmmedv log_spending log_ave_ex_size ally log_distance contiguity colony_unit if abbrev1!="USA", vce(cluster dyad)
mchange
mchangeplot postcoldwar lagmmedv log_spending ally log_ave_ex_size log_distance contiguity colony_unit, varlabels graphregion(color(white)) sig(.05)

* Figure 9: Marginal Change Plot for Model 4 *
quietly mlogit mmedv postcoldwar lagmmedv log_spending log_ave_ex_size ally log_distance contiguity colony_unit if abbrev1=="RUS", vce(cluster dyad)
mchange
mchangeplot postcoldwar lagmmedv log_spending ally log_ave_ex_size log_distance contiguity colony_unit, varlabels graphregion(color(white)) sig(.05)

** End of file **
clear
